<?php

namespace App\Http\Controllers;

use App\LanguageModel;
use Illuminate\Http\Request;

class LanguageController extends Controller
{
    public function addlangauge()
    {
        return view("admin.addlang");
    }


    public function langs(Request $request)
    {
        $langs = LanguageModel::get();
        return view("admin.langs", compact("langs"));
    }


    public function updatelang(Request $request)
    {
        $id = $request->input('id');
        $lang = LanguageModel::where("id", $id)->first();
        return view("admin.addlang", compact("lang"));
    }


    public function deletelang(Request $request)
    {
        $id = $request->input('id');
        $lang = LanguageModel::where("id", $id)->delete();
        $result = ["title" => "记录已删除", "err" => 0];
        $result = json_encode($result);
        return $result;
    }


    public function langinsert(Request $request){
        $lang = $request->input();
        $id = $lang['id'];
        if ($id==0){
            LanguageModel::create($lang);
            $result = ["title" => "数据添加成功", "err" => 0];
            $result = json_encode($result);
            return $result;
        }else{
           $up= LanguageModel::where("id",$id)->first();
         $up->update($lang);
            $result = ["title" => "数据修改成功", "err" => 0];
            $result = json_encode($result);
            return $result;
        }
    }
}
